package Dao;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import Entity.MyExcellentCourse_student;
import OracleHelper.OracleHelper;

public class MyExcellentCourse_studentDao {
	
	/*向courseResource表中插入数据*/
	public int addMyExcellentCourse(MyExcellentCourse_student mec) {
		String sql="insert into myExcellentCourse values('"+mec.getStudentNo()+"','"+mec.getCourseID()+"',"
				+ "'"+mec.getLabel()+"','"+mec.getCourseName()+"','"+mec.getUploaderID()+"','"+mec.getUploadTime()+"','"+mec.getBriefIntroduce()+"')";
		return new OracleHelper().executeUpdate(sql);
		
	}
	
	/*删除一条信息*/
	public int deleteCourseResourceByStudentNo(String studentNo) {
		String sql="delete from myExcellentCourse where studentNo='"+studentNo+"'";
		return new OracleHelper().executeUpdate(sql);
		
	}
	
	/*通过学号查询该学生所有下载的精品课程*/
	public List<MyExcellentCourse_student> queryMyExcellentCourseByStudentNo(String studentNo){
		List<MyExcellentCourse_student> meclist=new ArrayList<MyExcellentCourse_student>();
		String sql="select * from myExcellentCourse where studentNo='"+studentNo+"'";
		ResultSet rs=OracleHelper.executeQuery(sql);
		try{
			while(rs.next()){
				MyExcellentCourse_student mec=new MyExcellentCourse_student();
				mec.setStudentNo(rs.getString(1));
				mec.setCourseID(rs.getString(2));
				mec.setLabel(rs.getString(3));
				mec.setCourseName(rs.getString(4));
				mec.setUploaderID(rs.getString(5));
				mec.setUploadTime(rs.getString(6));
				mec.setBriefIntroduce(rs.getString(7));
				meclist.add(mec);
			}
			OracleHelper.closeConnection();;
		}catch(Exception ex){
			ex.printStackTrace();
		}
		return meclist;			
	}

}
